package com.pushmessgae.server.config;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;

public final class SysConfig {

	private static final String filePath = "/system.properties";
	
	private static SysConfig config ;
	
	private static final Properties PROPERTIES = new Properties();

	private SysConfig() {
		load();
	}
	
	public static SysConfig getInstance(){
		if(null == config){
			config = new SysConfig();
		}
		return config;
	}

	private void load(){
		try {
			final Reader reader = new InputStreamReader(getClass().getResourceAsStream(filePath), "UTF-8"); 
			PROPERTIES.load(reader );
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public String getString(String key){
		return null == PROPERTIES ? null : PROPERTIES.getProperty(key);
	}
	
	public int getInt(String key){
		final String value = getString(key) ;
		if(null != value){
			return Integer.parseInt(value);
		}
		return -1;
	}

}
